﻿using System.Windows;
using System.Windows.Controls;

using Game.Editor.Toolbox;
using Game.Map;

namespace Game.Editor
{
    public partial class MapEditorControl : UserControl
    {
        readonly EditorSurfaceControl2 _SurfaceControl;

        string _Filename;

        public MapEditorControl(IGameMap map)
        {
            InitializeComponent();
            Init();

            _SurfaceControl = new EditorSurfaceControl2(map);

            Canvas.SetLeft(_SurfaceControl, 20);
            Canvas.SetTop(_SurfaceControl, 20);

            this.canvas2.Children.Add(_SurfaceControl);
        }

        public string Filename
        {
            get { return _Filename; }
            set { _Filename=value; }
        }

        public EditorSurfaceControl2 SurfaceControl
        {
            get { return _SurfaceControl; }
        }

        void Init()
        {
            SelectionController controller = new SelectionController();
            controller.Start();

            Accordion accordian = new Accordion();
            grid1.Children.Add(accordian);
            accordian.Height = double.NaN;
            accordian.Width = double.NaN;
            accordian.MaxWidth = 300;
            accordian.VerticalAlignment = System.Windows.VerticalAlignment.Stretch;
            accordian.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch;
            accordian.SelectionMode = AccordionSelectionMode.One;

            AddControl(accordian, new TerrainControl2(), "Terrain");
            AddControl(accordian, new VehicleControl2(), "Vehicles");
            AddControl(accordian, new StandardTerrainControl2(), "Terrain Objects");
            AddControl(accordian, new InfrastructureControl2(), "Infrastructure");
            AddControl(accordian, new BuildingControl2(), "Buildings");
        }

        void AddControl(Accordion accordian, UserControl c, string header)
        {
            c.Height = double.NaN;
            c.Width = double.NaN;
            c.VerticalAlignment = System.Windows.VerticalAlignment.Stretch;
            c.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch;
            AccordionItem item = new AccordionItem();
            item.Content = c;
            item.Header = header;
            accordian.Items.Add(item);
        }

        void slider1_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            if (_SurfaceControl != null)
            {
                _SurfaceControl.GameScale = (e.NewValue / 100d);
            }
        }

    }
}
